<?php

namespace app\common\model\system;


use app\common\model\TimeModel;

class SystemAdmin extends TimeModel
{

    protected $deleteTime = 'delete_time';

    public function getAuthList()
    {
        $list = (new SystemAuth())
            ->where('status', 1)
            ->column('title', 'id');
        return $list;
    }
    /**
     * 定义全局的查询范围
     * @param \think\db\Query $query
     */
    public function scopeApp_id($query)
    {
        return true;
    }

    //所属商家
    public function Store()
    {
        return $this->belongsTo('app\common\model\mall\Store','store_id','id')->field('id,name,phone');
    }

    //所属角色
    public function role()
    {
        return $this->belongsTo('app\common\model\system\SystemAuth','auth_ids','id')->field('id,permission');
    }

    public static function onAfterDelete($data){
        $stora = app('app\common\model\mall\Store');
        if($data['is_store']==1){
            $admin = $stora::where('id',$data['store_id'])->select();
            $admin->delete();
        }
        
    }

}